<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>注册</title>
	</head>

	<body>
		<p>
			用户 <input type="text" name="username" id="username" value="" />
		</p>
		<p>
			密码 <input type="password" name="password" id="password" value="" />
		</p>
		<p>
			确认密码 <input type="password" name="password2" id="password2" value="" />
		</p>
		<p>
			<input type="button" name="btn" id="btn" value="注册" />
			<a href="login.html">已有帐号去登录</a>
		</p>
	</body>
	<script src="js/jquery-3.2.1.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$("input[name=btn]").click(function() {
			var user = $("input[name=username]").val();
			var pas = $("input[name=password]").val();
			$.ajax({
				type: "post",
				url: "http://h6.duchengjiu.top/shop/api_user.php",
				async: true,
				data: {
					status: "register",
					username: user,
					password: pas
				},
				success: function(data) {
					console.log(data);
					if (data.code == 2001) {
						alert("用户名已存在");
						return;
					}
					if (data.code == 0) {
						alert("注册成功");
						location.href = 'login.html';
					}
				}
			});

		});
	</script>

</html>